<template>
    <div class="app-container calendar-list-container"> 
        <!-- 搜索框，对工段信息进行搜索 -->
      <el-form :inline="true" ref="listQuery" :rules="rules" :model="listQuery">
        <el-form-item prop="orderPlanNo">
            <el-input
                clearable
                style="width: 200px;"
                v-model="listQuery.orderPlanNo"
                class="filter-item"
                placeholder="计划批号"
            ></el-input>
        </el-form-item>
        <el-form-item>
            <el-button class="filter-item" type="primary" :loading="loading" v-waves @click="submitForm('listQuery')">上线</el-button>
        </el-form-item>
      </el-form>
    </div>
</template>

<script>
import { planOnlineOrderPlanNo } from '@/api/CNCmachine.js'
export default {
    name: 'planOnline',
    data() {
        return {
            listQuery: {
                orderPlanNo: ''
            },
            rules: {
                orderPlanNo: [
                    { required: true, message: '计划批号不能为空！', trigger: 'blur' }
                ]
            },
            loading: false
        }
    },
    methods: {
        // 提交表单之前先进行验证
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
            if (valid) {
                this.planOnlineOrder()
            } else {
                return false
                }
            })
        },

        async planOnlineOrder(){
            
            this.loading = true

            let query = Object.assign({},this.listQuery)

            let data = await planOnlineOrderPlanNo(query)

            this.loading = false

            if(data.code == '2') return this.$message.error(data.msg)

            this.$message.success(data.msg)

            this.resetForm('listQuery')
        },
        // 对整个表单输入进去清空
        resetForm(formItem) {
          this.$refs[formItem].resetFields()
        }
    },
      // 在生命周期函数调用"搜索"按钮绑定的函数，显示已有的数据
    mounted() {
  },
}
</script>

<style>

</style>
